package com.JingYan.controller;

import com.JingYan.domain.AjaxResult;
import com.JingYan.domain.SysUser;
import com.JingYan.domain.page.PageDomain;
import com.JingYan.service.SysUserService;
import com.JingYan.util.sql.SqlUtil;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author DongJiaQi
 * @create 2022/10/13 14:31
 * @Description:
 */
@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {
    @Autowired
    SysUserService sysUserService;
    @PostMapping("/testList")
    public List<SysUser> testList(@RequestBody SysUser sysUser){
        return sysUserService.getByid(sysUser.getUserId());
    }


    /**
     * 不分页但依旧要支持页面字段排序
     * @param pageDomain
     * @return
     */
    @PostMapping("/pageDomainAndOrderByOnly")
    public AjaxResult pageDomainAndOrderByOnly( @RequestBody PageDomain pageDomain){
        String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
        PageHelper.startPage(1, 0, orderBy).setReasonable(true).setOrderByOnly(true);
        List<Object> list = new ArrayList<>();
        return AjaxResult.success(list);
    }
}
